πŸ§ͺ ACID Principles Β· Interactive Lesson

⚑ One bank transfer. One power outage. What saves your money?

What is ACID?

ACID is a set of four properties that guarantee database transactions are processed reliably. Think of a transaction as a single operation (like transferring money or booking a flight).

AAtomicity – All or nothing CConsistency – Valid data only IIsolation – No chaotic interference DDurability – Survives catastrophe

Let's explore each one through real scenarios. We'll start with a broken algorithm and see what goes wrong.

Scenario 1: The Broken Transfer

Imagine a simple banking app that transfers $1,000 from Savings to Checking. Here's the code it runs:

1. Read balance of Savings β†’ $2,000 2. Subtract $1,000 β†’ write $1,000 back to disk 3. Read balance of Checking β†’ $500 4. Add $1,000 β†’ write $1,500 back to disk 5. Send "Success" email

The problem? If the power fails between steps 2 and 4, the money leaves Savings but never arrives in Checking. Your $1,000 vanishes. The database is in a partial, corrupted state.

❓ Question 1 β€” What fundamental database property is missing from this algorithm?